package org.dizem.util;

/**
 * User: dizem@126.com
 * Time: 11-7-2 上午11:08
 */
public class Pager {

	private Integer page = 0;

	private Integer recordSize = -1;

	private Integer pageSize = 10;

	private Integer pageCount = 1;

	private Integer currentPage = 1;

	private Integer startPage = 1;

	private String fileName = "";

	private boolean useUrlRewrite = false;

	public Pager() {
	}

	public Pager(Integer page, Integer totalNum, Integer perPageNum) {
		this.page = page;
		this.recordSize = totalNum;
		this.pageSize = perPageNum;
		this.executeCount();
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getRecordSize() {
		return recordSize;
	}

	public void setRecordSize(Integer recordSize) {
		this.recordSize = recordSize;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getPageCount() {
		return pageCount;
	}

	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getStartPage() {
		return startPage;
	}

	public void setStartPage(Integer startPage) {
		this.startPage = startPage;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public boolean isUseUrlRewrite() {
		return useUrlRewrite;
	}

	public void setUseUrlRewrite(boolean useUrlRewrite) {
		this.useUrlRewrite = useUrlRewrite;
	}

	public void executeCount() {
		this.pageCount = (int) Math.ceil((this.recordSize + this.pageSize - 1)
				/ this.pageSize);
		int intPage = this.page;
		if (intPage > this.pageCount) {
			this.currentPage = 1;
		} else {
			this.currentPage = intPage;
		}
		if (this.currentPage <= 0) {
			this.startPage = 1;
		} else {
			this.startPage = (this.currentPage - 1) * this.pageSize;
		}
	}
}